package com.zhuchaooasystem.adapter.holder;

import android.text.TextUtils;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.jude.easyrecyclerview.adapter.BaseViewHolder;
import com.zhuchaooasystem.R;
import com.zhuchaooasystem.entity.RecordDetailEntity;
import com.zhuchaooasystem.ui.home.fragment.oa.record.RecordDetailActivity;

/**
 * @author yinsi
 */
public class RecordDetailHolder extends BaseViewHolder<RecordDetailEntity.ResultBean.SuccessfulBean> {
    private TextView tv_path;
    private TextView tv_time;
    private ImageView iv_control;
    private int position;
    //----
    private RecordDetailActivity activity;

    public RecordDetailHolder(ViewGroup parent, RecordDetailActivity activity) {
        super(parent, R.layout.item_activity_record_detail);
        this.activity = activity;
        tv_path = $(R.id.item_act_record_detail_txt_path);
        tv_time = $(R.id.item_act_record_detail_txt_time);
        iv_control = $(R.id.item_act_record_detail_iv_control);
    }

    @Override
    public void setData(final RecordDetailEntity.ResultBean.SuccessfulBean entity) {
        position = getDataPosition();
        //----
        int cur_position = activity.getCur_position();
        //该音乐正在播放
        if (cur_position == position) {
            iv_control.setImageResource(R.drawable.ic_record_stop);
        } else {
            iv_control.setImageResource(R.drawable.ic_record_play);
        }
        //----
        tv_path.setText(entity.getFilePath().substring(entity.getFilePath().lastIndexOf("/") + 1));
        tv_time.setText("录音总时长 " + (TextUtils.isEmpty(entity.getOften()) ? "00:00:00" : entity.getOften()));
        //----
        iv_control.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                activity.onClickPlay(position);
            }
        });
    }

}
